package handler

import (
	"2302a/audio_podcast/api/request"
	"2302a/audio_podcast/api/resp"
	"2302a/audio_podcast/internal/dao"
	"2302a/audio_podcast/internal/model"
	"2302a/audio_podcast/pkg"
	"github.com/gin-gonic/gin"
)

func AddAudio(c *gin.Context) {
	var req request.AddAudio
	err := c.ShouldBind(&req)
	if err != nil {
		resp.Error(c, 10000, "参数信息错误", err.Error())
		return
	}
	var user model.Users
	userId := c.GetUint("userId")
	dao.GetOneById(userId, &user)
	if user.Id == 0 {
		resp.Error(c, 10000, "用户不存在", nil)
		return
	}
	audio := model.Audios{
		AudioName: req.AudioName,
		Describe:  req.Describe,
		UserId:    userId,
		VideoUrl:  req.VideoUrl,
	}
	if !pkg.Sensitive(req.AudioName) {
		resp.Error(c, 10000, "实现敏感词过滤", nil)
		return
	}
	dao.Create(&audio)
	resp.Success(c, "音频发布成功", true)
}

func AddEpisode(c *gin.Context) {

	var req request.AddEpisodes
	err := c.ShouldBind(&req)
	if err != nil {
		resp.Error(c, 10000, "参数信息错误", err.Error())
		return
	}
	var user model.Users
	userId := c.GetUint("userId")
	dao.GetOneById(userId, &user)
	if user.Id == 0 {
		resp.Error(c, 10000, "用户不存在", nil)
		return
	}
	var audio model.Audios
	dao.GetOneById(req.AudiosId, &audio)
	if audio.Id == 0 {
		resp.Error(c, 10000, "音频不存在", nil)
		return
	}
	episodes := model.Episodes{
		AudiosId: req.AudiosId,
		Title:    req.Title,
	}
	dao.Create(&episodes)
	resp.Success(c, "音频剧集成功", true)
}

func ListAudio(c *gin.Context) {

}
